﻿using System;
using System.Windows;
using System.Windows.Controls;
using BaMusaSoft.RPS.DataModel;
using BaMusaSoft.RPS.ViewModel;

namespace BaMusaSoft.RPS.View
{
    /// <summary>
    /// Interaction logic for AddContractWindow.xaml
    /// </summary>
    public partial class AddContractWindow : Window
    {
        private readonly AddContractViewModel _viewModel;

        public AddContractWindow()
        {
            InitializeComponent();
        }

        public AddContractWindow(AddContractViewModel viewModel) : this()
        {
            if (viewModel == null) throw new ArgumentNullException("viewModel");
            _viewModel = viewModel;
            DataContext = _viewModel;
        }

        private void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void OkButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void ItemSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((AddContractViewModel) DataContext).SelectedContract = ((ListBox) sender).SelectedItem as Contract;
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            txtCustomerName.Focus();
        }
    }
}